home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / internet / sweeper / samples / olecon~1 / framewrk / unknown.cpp < prev    next >
Text File  |  1995-11-25  |  4KB  |  140 lines

  1. //=--------------------------------------------------------------------------=
  2. // Unknown.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright  1995  Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // implementation for various things in the unknown object that supports
  13. // aggregation.
  14. //
  15. #include "IPServer.H"
  16. #include "Unknown.H"
  17. #include <stddef.h>
  18.  
  19.  
  20. //=--------------------------------------------------------------------------=
  21. // CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  22. //=--------------------------------------------------------------------------=
  23. // this method is used when we're sitting in the private unknown object,
  24. // and we need to get at the pointer for the main unknown.  basically, it's
  25. // a little better to do this pointer arithmetic than have to store a pointer
  26. // to the parent, etc.
  27. //
  28. inline CUnknownObject *CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  29. (
  30.     void
  31. )
  32. {
  33.     return (CUnknownObject *)((LPBYTE)this - offsetof(CUnknownObject, m_UnkPrivate));
  34. }
  35.  
  36. //=--------------------------------------------------------------------------=
  37. // CUnknownObject::CPrivateUnknownObject::QueryInterface
  38. //=--------------------------------------------------------------------------=
  39. // this is the non-delegating internal QI routine.
  40. //
  41. // Parameters:
  42. //    REFIID        - [in]  interface they want
  43. //    void **       - [out] where they want to put the resulting object ptr.
  44. //
  45. // Output:
  46. //    HRESULT       - S_OK, E_NOINTERFACE
  47. //
  48. // Notes:
  49. //
  50. STDMETHODIMP CUnknownObject::CPrivateUnknownObject::QueryInterface
  51. (
  52.     REFIID riid,
  53.     void **ppvObjOut
  54. )
  55. {
  56.     CHECK_POINTER(ppvObjOut);
  57.  
  58.     // if they're asking for IUnknown, then we have to pass them ourselves.
  59.     // otherwise defer to the inheriting object's InternalQueryInterface
  60.     //
  61.     if (DO_GUIDS_MATCH(riid, IID_IUnknown)) {
  62.         m_cRef++;
  63.         *ppvObjOut = (IUnknown *)this;
  64.         return S_OK;
  65.     } else
  66.         return m_pMainUnknown()->InternalQueryInterface(riid, ppvObjOut);
  67.  
  68.     // dead code    
  69. }
  70.  
  71. //=--------------------------------------------------------------------------=
  72. // CUnknownObject::CPrivateUnknownObject::AddRef
  73. //=--------------------------------------------------------------------------=
  74. // adds a tick to the current reference count.
  75. //
  76. // Output:
  77. //    ULONG        - the new reference count
  78. //
  79. // Notes:
  80. //
  81. ULONG CUnknownObject::CPrivateUnknownObject::AddRef
  82. (
  83.     void
  84. )
  85. {
  86.     return ++m_cRef;
  87. }
  88.  
  89. //=--------------------------------------------------------------------------=
  90. // CUnknownObject::CPrivateUnknownObject::Release
  91. //=--------------------------------------------------------------------------=
  92. // removes a tick from the count, and delets the object if necessary
  93. //
  94. // Output:
  95. //    ULONG         - remaining refs
  96. //
  97. // Notes:
  98. //
  99. ULONG CUnknownObject::CPrivateUnknownObject::Release
  100. (
  101.     void
  102. )
  103. {
  104.     ULONG cRef = --m_cRef;
  105.  
  106.     if (!m_cRef)
  107.         delete m_pMainUnknown();
  108.  
  109.     return cRef;
  110. }
  111.  
  112.  
  113. //=--------------------------------------------------------------------------=
  114. // CUnknownObject::InternalQueryInterface
  115. //=--------------------------------------------------------------------------=
  116. // objects that are aggregated use this to support additional interfaces.
  117. // they should call this method on their parent so that any of it's interfaces
  118. // are queried.
  119. //
  120. // Parameters:
  121. //    REFIID        - [in]  interface they want
  122. //    void **       - [out] where they want to put the resulting object ptr.
  123. //
  124. // Output:
  125. //    HRESULT       - S_OK, E_NOINTERFACE
  126. //
  127. // Notes:
  128. //
  129. HRESULT CUnknownObject::InternalQueryInterface
  130. (
  131.     REFIID  riid,
  132.     void  **ppvObjOut
  133. )
  134. {
  135.     *ppvObjOut = NULL;
  136.  
  137.     return E_NOINTERFACE;
  138. }
  139.  
  140.